 window.oncontextmenu = function(){return false;}
document.onkeydown = function (event) {
           var e=event.srcElement; 
            if(event.keyCode==13) 
            { 
            alert('确定修改文件名?');
            return true; 
            } 
	    } 
//加载php变量
//var root_path = '';
//以上是php变量

/**
 * 点击三小点
 */
function rquiek_like(t,hidecname){
	var w = $('#quick_menu').width();
	var rq_e = new Object();
		rq_e.which = 3;
		rq_e.pageY = $(t).offset().top + 5;
		rq_e.pageX = $(t).offset().left-w-10;
	var rq_t = $(t).parents('li');
	right_quick(rq_e,rq_t,hidecname)
}

//右键快捷   左键隐藏
function right_quick(e,t,hidecname){
	if(e.which == 3){
		$('#quick_menu .'+hidecname).hide();
		$('#quick_menu').css({'top':e.pageY,'left':e.pageX+3}).show();
		checkbox= $(t).find("tr td").find("input[type='checkbox']");
		
		
		cqo = $(t);
		//$('#file_wrap li').css('background-color','#fff');
		$(t).css('background-color','#d1e9e9');
		
		//加入当前li的背景色
	}else{
		$('#quick_menu').hide()
	}
}
//隐藏右键函数
function close_quick(){
	$('#quick_menu').hide();
}
//右键下的打开、
function quick_open(){
	change_dir(cqo)
	$('#quick_menu').hide()
}

//重命名
function rename_file(t){
	// $('#quick_menu').hide()
	// if(cqo.find('[name="newname"]').length>=1)return;
	// var filenameObj = cqo.find('.filename');
	// var oldname = filenameObj.html()
	// 	filenameObj.html('<input  onblur="submit_rename(this,\''+oldname+'\')" type="text" name="newname" value="'+oldname+'">');
	// filenameObj.children('[name="newname"]').focus().select()  //自动获取焦点 自动选择

	val = $(t).parent().parent().find("span").text();	
	$(t).parent().parent().children().eq(1).find("span").hide();
	 $("#before").remove();
	$(t).parent().parent().children().eq(1).find("span").after("<div id='before' style='display:inline'><input type='text' name='rename' value="+val+" autofocus><input type='button' name='' value='确定' onclick='rename(this)'><input type='button' name='' value='取消' onclick='connel_rename(this)'></div>");
	
}
function rename(t){
	var vid = $(t).parent().prev().attr("data-vid");
	var newname = $(t).prev().val();
	var oldname =$(t).parent().prev().text();
	var folder = $(t).parents("tr").children().eq(3).text();
	 $.ajax({
		"url":"?c=admin&m=main",
		"dataType":"json",
		"data":{"floder":folder,"newname":newname,"vid":vid,"oldname":oldname},
		"type":"post",
		success:function(re){
			if(re.code=='0'){
				alert("重命名成功");
				$(t).parent().prev().text(newname);
				$(t).parent().prev().show();
				$(t).parent().hide();
				//window.location.href="?c=admin&m=main";		
			}else{
				alert('重命名失败');
			}
		}
		});
}
function connel_rename(t){
	val = $(t).parent().prev().show();
	 $(t).parent("div").remove();

}
//根目录下建文件夹
function root_create(){
	//cqo = $('#root_path');		
	var dirname = $("#addir").val();			
	 if(dirname==''||dirname=='undefined'){
	 	alert("文件夹名不能为空");	 	
	 	return false;
	 }else{
	 	$("#addir").remove();
	 	$(":checkbox:checked").after( "<span id='notnull'>"+dirname+"</span>");
	 }
	var notnull = $(":checkbox:checked").next().text();
	if(notnull==""){
		alert("不能为空");
	}			
	//alert(dirname);		
		create_dir(dirname);
		$("#confirm").hide();
}


function insertInput(){
   show = $("#confirm").is(':visible');
	$("#confirm").show();
	if(show ==true){
		alert("先完上一个文件夹成创建");
		return false;
	}

	var checkbox  = $("table").find("input[type='checkbox']");

    var isChecked = checkbox.is(":checked");

    var dirname = $("#addir").val();
    if(isChecked){
   	 checkbox.removeAttr("checked");	
    }
	imgsrc='/file_service/resource/img/dir.png';
	
	data = "<tr onmousedown=right_quick(event,this,'file') id='removetr' ><td><input type='checkbox'  name='vehicle' value= "+dirname+" class='checkbox'  /></td><td ><img src="+imgsrc+" id='images'><input type='checkbox'  style='display: none;' name='vehicle' value= "+dirname+" class='checkbox' checked='checked' /><input  clas='addir' id='addir'  type='text'  name='fileName' autofocus='autofocus' value=''> </td><td></td><td></td> <td class='last'><input class='lookbtn' name='' style='' type='button' value='查看'></td><td class='last'><input type='button' name='' value='重命名'></td></tr>";
	//$("#tablehide").prepend(data);//从后面插入
	$("#tablehide").find("tr").first().after(data);//从前面插入
	
}

function removeFile(){
		//$("#w3s").attr("href")
	 filename  = [];//存放选择的文件数组
	  $.each($('input:checkbox'),function(){
                if(this.checked){
                   filename.push($(this).val());
                }	
            });
	  var root_path = "602206/";//这里为商户号
	  var targetfolder=$('input:radio[name="vehicle"]:checked').val();
	  var nowfolder = "602206/";

	  if(targetfolder==undefined){
	  	
		alert("请选择一个文件夹");
	  		return false;
	  }
	   $.ajax({
		"url":"?c=FileHandle&m=remove",
		"dataType":"json",
		"data":{"nowfolder":nowfolder,"targetfolder":targetfolder+"/","root_path":root_path,"filename":filename},
		"type":"post",
		success:function(re){
			if(re.code=='0'){
				alert("移动成功");	
				window.location.href="?c=admin&m=main";		
			}else{
				alert('移动失败，请刷新网页重试');
			}
		}
		});


	 
	
}
   function menu_close(){
	   	$("#folder_menu").hide();
	   }
